# Maintainer: Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Dan McGee <dan@archlinux.org>

pkgname=irssi
replaces=(irssi-git)
conflicts=(irssi-git)
pkgver=1.2.2
pkgrel=1
pkgdesc="Modular text mode IRC client with Perl scripting"
arch=('i686' 'x86_64')
url="https://irssi.org/"
license=('GPL')
depends=('openssl' 'gettext' 'perl' 'ncurses' 'glib2')
makedepends=('gettext-devel' 'glib2-devel' 'openssl-devel' 'libcrypt-devel' 'ncurses-devel' 'pcre-devel' 'elinks')
optdepends=('perl-libwww: for the scriptassist script')
backup=('etc/irssi.conf')
source=("https://github.com/irssi/${pkgname}/releases/download/${pkgver}/${pkgname}-${pkgver}.tar.xz"{,.asc}
        "0000_msysize.patch")
options=('!strip')
sha256sums=('6727060c918568ba2ff4295ad736128dba0b995d7b20491bca11f593bd857578'
            'SKIP'
            'ec2dc647191717c4abd9b86a51c085e9bb8ca13998726ef0be97f4d213577eb3')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  # echo 'Autogen preventing configure until later'
  # NOCONFIGURE=1 ./autogen.sh
  echo 'Applying patches simply adding #msys2 to default config'
  patch -p1 -i ${srcdir}/0000_msysize.patch
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  ./configure \
    --build=${CHOST} \
    --sysconfdir=/etc \
    --prefix=/usr \
    --disable-glibtest \
    --with-perl-lib=vendor \
    --with-perl-staticlib

  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  echo 'Applying patches to Perl MakeMaker library misname'
  find . -name "Makefile" -type f | while read line; do sed -i 's/\([i|c|I]\)\.dll$/\1.a/' $line; done
  
  make DESTDIR="${pkgdir}" install
}
